<?php
namespace app\admin\controller;

class Admin extends Base
{

    public function lst()
    {
        $lst=model('admin')->paginate(10);
        $viewData=[
            'lst'=>$lst,
        ];
        $this->assign($viewData);
        return view();
    }

    /**
     * 添加管理员
     * @return \think\response\View
     */
    public function add()
    {
        if(request()->isPost()){
            $data=request()->param();
            $data['create_time']=time();
            $res=model('admin')->addM($data);
            if($res==1){
                $this->success('添加成功');
            }else{
                $this->error($res);
            }
        }
        return view();
    }

    /**
     * 编辑管理员
     * @return \think\response\View
     */
    public function edit()
    {
        if(request()->isPost()){
            $data=request()->param();
            $res= model('admin')->editM($data);
            if($res==1){
                return $this->success('修改成功');
            }else{
                return $this->error($res);
            }
        }

        $id=request()->param('id');
        $cur_id_info=model('admin')->getOne($id);
        if(empty($cur_id_info)){
            return $this->error('查询数据失败！');
        }
        $viewData=[
            'cur_id_info'=>$cur_id_info,
        ];
        $this->assign($viewData);
        return view();
    }

    public function del()
    {
        if(request()->isGet()){
            $id=request()->param('id');
            $res=model('admin')->delM($id);
            if($res){
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }
    }

}
